// pages/order-info/order-info.js
var util = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    totalPrice: null,
    alltotalPrice: null,
    hidden: false,
  },

  del(e) {
    var id = e.currentTarget.dataset.id
    var that = this;
    wx.showModal({
      title: '',
      content: '是否确认删除',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
          wx.request({
            url: 'http://localhost/shopping/admin_order_del.php',
            header: {
              'Content-Type': 'application/json'
            },
            data: {
              id: id
            },
            success: function (res) {
              // console.log(res.data)
              that.setData({})
            },
            fail: function (res) {
              console.log("fail");
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    // console.log(e.ordernumber)
    var id = e.id
    var that = this;
    wx.request({
      url: 'http://localhost/shopping/order_info.php',
      header: {
        'Content-Type': 'application/json'
      },
      data: {
        id: id
      },
      success: function (res) {
        // console.log(res.data)
        if (res.data.orderssearch[0].tracking == null) {
          that.setData({
            hidden: !that.data.hidden,
          })
        }
        that.setData({
          arrsearch: res.data.orderssearch,
          type: res.data.orderssearch[0].type,
          totalPrice: Number(res.data.orderssearch[0].goodsprice * res.data.orderssearch[0].goodsnumber),
          alltotalPrice: Number(res.data.orderssearch[0].goodsprice * res.data.orderssearch[0].goodsnumber),
        })
      },
      fail: function (res) {
        console.log("fail");
      }
    })
    let name = getApp().globalData.usersname
    wx.request({
      url: 'http://localhost/shopping/users.php',
      header: {
        'Content-Type': 'application/json'
      },
      data: {
        name: name
      },
      success: function (res) {
        console.log(res.data)
        that.setData({
          arraa: res.data.users,
        })
      },
      fail: function (res) {
        console.log("fail");
      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function (e) {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})